<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <title>oi管理系统</title>
  <style>
    table,th,td{
      border: 1px solid black;
      border-collapse: collapse;
      padding: 5px;
    }

  </style>
</head>
<body>
<table>
  <thead>
  <tr>
    <th>ID</th>
    <th>姓名</th>
    <th>年龄</th>
    <th>地址</th>
    <th>操作</th>
  </tr>
  </thead>

  <tbody>
  <c:forEach var="man" items="${mans}">
    <tr>
      <td>"${man.id}"</td>
      <td>"${man.name}"</td>
      <td>"${man.age}"</td>
      <td>"${man.diZhi}"</td>
      <td>"${man.major}"</td>
      <td>
          <%--修改--%>
        <form action="${pageContext.request.contextPath}/mans" method="post">
          <input type="hidden" name="action" value="update">
          <input type="hidden" name="id" value="${man.id}">

          <input type="text" name="name" placeholder="请输入姓名" value="${man.name}">

          <input type="number" name="age" placeholder="请输入年龄" value="${man.age}">

          <input type="text" name="diZhi" placeholder="请输入地址" value="${man.diZhi}" >

          <input type="text" name="major" placeholder="请输入操作" value="${man.major}">

          <button type="submit">更新</button>
        </form>
          <%-- 删除 --%>
        <form action="${pageContext.request.contextPath}/mans" method="post" onsubmit="return confirm('确定要删除吗')">
          <input type="hidden" name="action" value="delete">
          <input type="hidden" name="id" value="${man.id}">
          <button type="submit">删除</button>
        </form>
      </td>
    </tr>
  </c:forEach>
  </tbody>
</table>

<%--新增--%>
<h2>添加新学生</h2>

<form action="${pageContext.request.contextPath}/mans" method="post">
  <input type="hidden" name="action" id="action" value="add">

  <label for="name">学生姓名</label>
  <input type="text" id="name" name="name" placeholder="请输入姓名" value="${man.name}"><br>

  <label for="age">学生年龄</label>
  <input type="number" id="age" name="age" placeholder="请输入年龄" value="${man.age}"><br>

  <label for="diZhi">学生地址</label>
  <input type="text" id="diZhi" name="gender" placeholder="请输入地址" value="${man.diZhi}" maxlength="1"><br>

  <label for="major">相关操作</label>
  <input type="text" id="major" name="major" placeholder="请输入操作" value="${man.major}"><br>

  <input type="submit"><input type="reset">
</form>

</body>
</html>
